<?php
function TopTypes()
{
	$m=M("Type");
	$list=$m->where("parent_id=0")->select();
	return $list;
}

//获取格式化时间
function getFormatTime(){
	return date('Y-m-d H:i:s');
}

function TypeTree()
{
	$m=M("Type");
	$list=$m->order("parent_id asc")->select();
	//echo $m->getLastSql();

	$typelist=array();
	
	foreach ($list as $v){
		if($v['parent_id']==0){
			$typelist[$v['Id']]=$v;
			$typelist[$v['Id']]['sublist']=array();
		}else{
			$typelist[$v['parent_id']]['sublist'][]=$v;
		}
	}
	return $typelist;
}

function TypeName($type_id)
{
	static $ret=array();
	
	if(isset($ret[$type_id])){
		return $ret[$type_id];
	}else{
		$m=M("Type");
		$m->getById($type_id);
		$ret[$type_id]=$m->typename;
		return $m->typename;
	}
}

function setUser($user)
{
	session("ADMIN",$user);
}

function getUserId()
{
	if(session("?ADMIN")) {
		$user=session("ADMIN");
		return $user['Id'];
	}else
		return 0;
}

function checkUser($username,$password){
	$m=M("Admin");
	$data=$m->where("username='$username'")->find();
	if($data && $m->status==1 &&  $m->password==md5($password)){
		return $data;
	}
	else
	{
		return false;
	}
}

function unsetUser()
{
	session("ADMIN",null);
	return true;
}

function ProductType($type)
{
	$array=array('jingji'=>'经济套餐','tehui'=>'特惠套餐');
	return $array[$type];
}